package org.budo.sharding.spi.database;

import org.apache.shardingsphere.spi.database.DataSourceMetaData;
import org.budo.jdbc.driver.JdbcUrl;

/**
 * @author lmw
 * @see org.apache.shardingsphere.core.metadata.datasource.dialect.MySQLDataSourceMetaData
 */
public class BudoShardingDataSourceMetaData implements DataSourceMetaData {
    private JdbcUrl jdbcUrl;

    public BudoShardingDataSourceMetaData(String url, String[] urlPrefix, Integer defaultPort) {
        this.jdbcUrl = JdbcUrl.parse(url, urlPrefix, defaultPort);
    }

    public BudoShardingDataSourceMetaData(String url, String[] urlPrefix) {
        this.jdbcUrl = JdbcUrl.parse(url, urlPrefix, -1);
    }

    @Override
    public String getHostName() {
        return this.jdbcUrl.getHost();
    }

    @Override
    public int getPort() {
        return this.jdbcUrl.getPort();
    }

    @Override
    public String getCatalog() {
        throw new RuntimeException("#33 this=" + this);
    }

    @Override
    public String getSchema() {
        throw new RuntimeException("#38 this=" + this);
    }
}